package com.ayuku.course.util;

import java.util.List;

import org.eclipse.nebula.widgets.tablecombo.TableCombo;
import org.eclipse.swt.widgets.TableItem;

import com.ayuku.commons.SqliteDB;
import com.ayuku.commons.Util;
import com.ayuku.course.persistence.model.Category;
import com.ayuku.course.persistence.model.CourseLevel;

public class UtilCourse {

	public static void setCmbCourseLevel(TableCombo combo) throws Exception {
		Util.setCmbBasic(combo);
		List<CourseLevel> modelList = SqliteDB
		.getPersist()
		.readList(
				CourseLevel.class,
				"SELECT * FROM COURSE_LEVEL");
		
		int total = (modelList == null ? 0 : modelList.size());
		combo.getTable().setItemCount(total + 1);

		TableItem ti = combo.getTable().getItem(0);
		ti.setText(new String[] { "", "" });

		for (int index = 0; index < total; index++) {
			ti = combo.getTable().getItem(index + 1);
			CourseLevel model = modelList.get(index);
			ti.setText(new String[] { String.valueOf(model.getCode()),
					model.getName() });
		}

	}
	
	public static void setCmbCourseCategory(TableCombo combo) throws Exception {
		Util.setCmbBasic(combo);
		List<CourseLevel> modelList = SqliteDB
		.getPersist()
		.readList(
				CourseLevel.class,
				"SELECT * FROM COURSE_LEVEL");
		
		int total = (modelList == null ? 0 : modelList.size());
		combo.getTable().setItemCount(total + 1);

		TableItem ti = combo.getTable().getItem(0);
		ti.setText(new String[] { "", "" });

		for (int index = 0; index < total; index++) {
			ti = combo.getTable().getItem(index + 1);
			CourseLevel model = modelList.get(index);
			ti.setText(new String[] { String.valueOf(model.getCode()),
					model.getName() });
		}

	}

	public static void setCmbCategory(TableCombo combo) throws Exception {
		Util.setCmbBasic(combo);
		List<Category> modelList = SqliteDB
		.getPersist()
		.readList(
				Category.class,
				"SELECT * FROM CATEGORY");
		
		int total = (modelList == null ? 0 : modelList.size());
		combo.getTable().setItemCount(total + 1);

		TableItem ti = combo.getTable().getItem(0);
		ti.setText(new String[] { "", "" });

		for (int index = 0; index < total; index++) {
			ti = combo.getTable().getItem(index + 1);
			Category model = modelList.get(index);
			ti.setText(new String[] { String.valueOf(model.getCode()),
					model.getName() });
		}
	}
}
